function getGMapMarks() {
    GetMapMarks.getMapPoints(callback);
}
 
function callback(points) {
   loadMap(points);
}

var iconList = [];
var iconIndex = [];
var map;
    
function loadMap(points) {
  //if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    //map.addControl(new GMapTypeControl());
    map.addControl(new GSmallMapControl());
    
    // Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon();
	//baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	//baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
    

	var iconDefault = new GIcon(baseIcon);
  	iconDefault.image = "http://maps.google.com/mapfiles/kml/shapes/flag.png";

	var iconRed = new GIcon(baseIcon);
  	iconRed.image = "http://maps.google.com/mapfiles/kml/pushpin/red-pushpin.png";
	var iconYellow = new GIcon(baseIcon);
  	iconYellow.image = "http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png";
	var iconGreen = new GIcon(baseIcon);
  	iconGreen.image = "http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png";

    var iconPlane = new GIcon(baseIcon);
  	iconPlane.image = "http://maps.google.com/mapfiles/kml/shapes/airports.png";
  	var iconTruck = new GIcon(baseIcon);
  	iconTruck.image = "http://maps.google.com/mapfiles/kml/shapes/truck.png";
  	var iconTrain = new GIcon(baseIcon);
  	iconTrain.image = "http://maps.google.com/mapfiles/kml/shapes/rail.png";
  	
	iconList.push(iconDefault);		//0

	iconList.push(iconRed);			//1
  	iconList.push(iconYellow);		//2
  	iconList.push(iconGreen);		//3

	iconList.push(iconPlane);		//4
  	iconList.push(iconTruck);		//5
  	iconList.push(iconTrain);		//6
    

//    var sortPointsArr = []; 
//	sortPointsArr = GPoints.concat(); 
//	sortPointsArr.sort();
//	var leftPoint = sortPointsArr[0];
//	var rightPoint = sortPointsArr[nPoints - 1];
//	
//	var centerPoint = new GLatLng( (rightPoint.lat() + leftPoint.lat()) / 2,
//							   (rightPoint.lng() + leftPoint.lng()) / 2);

    showMap(points);
  //}
}

function showMap(points)
{
	var GPoints = [];
    var nPoints = points.length;
    var minLat, maxLat, minLng, maxLng;
    minLat = points[0].lat;
    maxLat = minLat;
    minLng = points[0].lng;
    maxLng = minLng;
    for(var i = 0; i < nPoints; i++)
    {
    	GPoints.push(new GLatLng(points[i].lat, points[i].lng));
    	if(points[i].lat < minLat)
    		minLat = points[i].lat;
    	if(points[i].lat > maxLat)
    		maxLat = points[i].lat;
    	if(points[i].lng < minLng)
    		minLng = points[i].lng;
    	if(points[i].lng > maxLng)
    		maxLng = points[i].lng;
    }
	var centerPoint = new GLatLng( (minLat + maxLat) / 2,
						   (minLng + maxLng) / 2);
	
	for(i = 0; i < GPoints.length; i++)
	{
		map.setCenter(centerPoint, 5);
		var marker = new GMarker(GPoints[i], iconList[points[i].iconIndex]);
	    map.addOverlay(marker);
	    if(i > 0 && i < GPoints.length)
	    {
		    if(points[i].lineColor == null)
	    		map.addOverlay(new GPolyline(GPoints.slice(i -1, i + 1),'#FF0000')); 
	    	else if(points[0].lineColor != "null")
	    		map.addOverlay(new GPolyline(GPoints.slice(i -1, i + 1), points[i - 1].lineColor)); 
	    }
    } 
//    if(points[0].lineColor == null)
//    	map.addOverlay(new GPolyline(GPoints,'#FF0000')); 
//    else
//    	map.addOverlay(new GPolyline(GPoints, points[0].lineColor)); 
}
